package com.java.study.invoker.enreka.interceptor;

import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;

public class RestInterceptor implements ClientHttpRequestInterceptor {

    @Override
    public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] body, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {

        System.out.println("============= 这是自定义拦截器实现");

        System.out.println(" 原来的 URI：" + httpRequest.getURI());

        RestHttpRequest restHttpRequest = new RestHttpRequest(httpRequest);

        System.out.println(" 拦截后新的 URI：" + httpRequest.getURI());

        return clientHttpRequestExecution.execute(restHttpRequest, body);

    }
}
